Patterns were learned on the 6mo MENs and the gut cell atlas was projected into them. Now look at the subset of non-fetal healthy samples and visualize the pattern usages

library(monocle3)
library(dplyr)
library(here)

source(here("scripts/accessory_functions/monocle_mods.R"))
source(here("scripts/accessory_functions/pattern_plotting.R"))
obj_fn <- "/data/users/jared/atlas_processing/gut_cell_atlas/data/mesenchymal_gut_nonfetal_healthy.Rds"

cds <- readRDS(obj_fn)

Pattern definitions in 6month LMMP

knitr::include_graphics(here("plots/NMF/lmmp/old_pattern_run/50dims/LMMP_pattern_feature_correlation.pdf"))
cell_wt <- data.table::fread(here("teichman_gut_atlas/data/gut_atlas_in_6mo_LMMP_old_patterns.csv"), data.table = F)
colnames(cell_wt)[1] <- "cell_index"

all(colnames(cds) %in% rownames(cell_wt))
## [1] FALSE

From previously generated pattern projections, load in values and merge with existing pData

pData(cds) <- pData(cds) %>%
  as.data.frame() %>%
  tibble::rownames_to_column(var = "cell_index") %>%
  left_join(., cell_wt, by = "cell_index") %>%
  tibble::column_to_rownames(var = "cell_index") %>%
  DataFrame
plot_cells_mod(cds, color_cells_by = "Age") + facet_wrap(~ Age)
## No trajectory to plot. Has learn_graph() been called yet?
## Warning: The `add` argument of `group_by()` is deprecated as of dplyr 1.0.0.
## Please use the `.add` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## `summarise()` has grouped output by 'cell_group'. You can override using the `.groups` argument.

plot_cells_mod(cds, color_cells_by = "Integrated_05", label_cell_groups = F) +
  theme(legend.position = "none") +
  facet_wrap(~ Integrated_05)
## No trajectory to plot. Has learn_graph() been called yet?

npatt <- 50
lapply(1:npatt, plotCellPatterns, cds, do.clip = c(0.01,0.99))
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## No trajectory to plot. Has learn_graph() been called yet?
## Cells aren't colored in a way that allows them to be grouped.
## Scale for 'colour' is already present. Adding another scale for 'colour',
## which will replace the existing scale.
## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

## 
## [[6]]

## 
## [[7]]

## 
## [[8]]

## 
## [[9]]

## 
## [[10]]

## 
## [[11]]

## 
## [[12]]

## 
## [[13]]

## 
## [[14]]

## 
## [[15]]

## 
## [[16]]

## 
## [[17]]

## 
## [[18]]

## 
## [[19]]

## 
## [[20]]

## 
## [[21]]

## 
## [[22]]

## 
## [[23]]

## 
## [[24]]

## 
## [[25]]

## 
## [[26]]

## 
## [[27]]

## 
## [[28]]

## 
## [[29]]

## 
## [[30]]

## 
## [[31]]

## 
## [[32]]

## 
## [[33]]

## 
## [[34]]

## 
## [[35]]

## 
## [[36]]

## 
## [[37]]

## 
## [[38]]

## 
## [[39]]

## 
## [[40]]

## 
## [[41]]

## 
## [[42]]

## 
## [[43]]

## 
## [[44]]

## 
## [[45]]

## 
## [[46]]

## 
## [[47]]

## 
## [[48]]

## 
## [[49]]

## 
## [[50]]

saveRDS(cds, here("teichman_gut_atlas/data/mesenchymal_gut_nfh_annotated.rds"))